<div id="products_detail">
<table border="0" cellpadding="0" cellspacing="0">

<?php 
if(isset($_GET['image'])){
	if(file_exists($dirname.$_GET['image']))
	unlink($dirname.$_GET['image']);
}

if(is_dir($dirname))
{
	$images = scandir($dirname);
	$numOfRow = 0;
	$ignore = Array(".", "..",".svn", "otherfiletoignore");
	//นับจำนวนไฟล์ 
	foreach($images as $curimg){
		if(!in_array($curimg, $ignore)) {
			$numOfRow++;
		}
	}
	if($numOfRow>0){
		$length = 1;
		//ดึงไฟล์มาแสดง
		foreach($images as $curimg){
			if(!in_array($curimg, $ignore)) {
				$curimg;
				$path = $dirname.$curimg;//str_replace("../../","",$src.$curimg);
				if($length == 1){
					echo "<tr valign=\"top\">
					<td>
						<a href=\"#\" onClick=\"dia_imagesAdd_delete('$dirname','$curimg')\" ><div class=\"BtnDelete\"></div></a>
						<img src=\"$path\" width=\"120\" height=\"100\" />
					</td>";
					if($length == $numOfRow) echo "</tr>";
				}else if($length % 5 > 0 && $length % 5 < 5){
					echo "<td>
						<a href=\"#\" onClick=\"dia_imagesAdd_delete('$dirname','$curimg')\" ><div class=\"BtnDelete\"></div></a>
						<img src=\"$path\" width=\"120\" height=\"100\" />				
				  </td>";
					if($length == $numOfRow) echo "</tr>";
				}else if($length % 5 == 0){
					echo "<td>
						<a href=\"#\" onClick=\"dia_imagesAdd_delete('$dirname','$curimg')\" ><div class=\"BtnDelete\"></div></a>
						<img src=\"$path\" width=\"120\" height=\"100\" />
				  		</td>
					</tr>";
					if($length != $numOfRow) echo "<tr valign=\"top\">";
				}
				$length++;
				$path = "";
			}
		}
	}else echo "<center><h3>No image<h3></center>";
} 
		?>
</table>
</div>